#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "tcpa_monitor.h"

void test_decode_input_parameter() {
    tcpa_monitor_t tcpam;
    memset(&tcpam, 0, sizeof(tcpam));

    // Test case 1: Happy path with both parameters
    char *argv1[] = { "program", "--tcpa_cfg_path", "/path/to/tcpa_cfg", "--whitelist_path", "/path/to/whitelist_cfg" };
    int argc1 = sizeof(argv1) / sizeof(argv1[0]);
    int result1 = decode_input_parameter(argc1, argv1, &tcpam);
    assert(result1 == 0);
    assert(strcmp(tcpam.tcpam_cfg_file_ctx.tcpa_cfg_file[TCPA_CFG].file_path, "/path/to/tcpa_cfg") == 0);
    assert(strcmp(tcpam.tcpam_cfg_file_ctx.tcpa_cfg_file[WHITELIST_CFG].file_path, "/path/to/whitelist_cfg") == 0);

    // Test case 2: Only tcpa_cfg_path provided
    char *argv2[] = { "program", "--tcpa_cfg_path", "/path/to/tcpa_cfg" };
    int argc2 = sizeof(argv2) / sizeof(argv2[0]);
    int result2 = decode_input_parameter(argc2, argv2, &tcpam);
    assert(result2 == 0);
    assert(strcmp(tcpam.tcpam_cfg_file_ctx.tcpa_cfg_file[TCPA_CFG].file_path, "/path/to/tcpa_cfg") == 0);
    assert(strlen(tcpam.tcpam_cfg_file_ctx.tcpa_cfg_file[WHITELIST_CFG].file_path) == 0);

    // Test case 3: Only whitelist_path provided
    char *argv3[] = { "program", "--whitelist_path", "/path/to/whitelist_cfg" };
    int argc3 = sizeof(argv3) / sizeof(argv3[0]);
    int result3 = decode_input_parameter(argc3, argv3, &tcpam);
    assert(result3 == 0);
    assert(strlen(tcpam.tcpam_cfg_file_ctx.tcpa_cfg_file[TCPA_CFG].file_path) == 0);
    assert(strcmp(tcpam.tcpam_cfg_file_ctx.tcpa_cfg_file[WHITELIST_CFG].file_path, "/path/to/whitelist_cfg") == 0);

    // Test case 4: Help option
    char *argv4[] = { "program", "--help" };
    int argc4 = sizeof(argv4) / sizeof(argv4[0]);
    int result4 = decode_input_parameter(argc4, argv4, &tcpam);
    assert(result4 == 0); // Help option should exit the program, so we can't test it here

    // Test case 5: Unknown parameter
    char *argv5[] = { "program", "--unknown_param", "value" };
    int argc5 = sizeof(argv5) / sizeof(argv5[0]);
    int result5 = decode_input_parameter(argc5, argv5, &tcpam);
    assert(result5 == -1);

    // Test case 6: Path too long for tcpa_cfg_path
    char long_path[256];
    memset(long_path, 'a', sizeof(long_path) - 1);
    long_path[sizeof(long_path) - 1] = '\0';
    char *argv6[] = { "program", "--tcpa_cfg_path", long_path };
    int argc6 = sizeof(argv6) / sizeof(argv6[0]);
    int result6 = decode_input_parameter(argc6, argv6, &tcpam);
    assert(result6 == -1);

    // Test case 7: Path too long for whitelist_path
    char *argv7[] = { "program", "--whitelist_path", long_path };
    int argc7 = sizeof(argv7) / sizeof(argv7[0]);
    int result7 = decode_input_parameter(argc7, argv7, &tcpam);
    assert(result7 == -1);

    printf("All test cases passed!\n");
}

int main() {
    test_decode_input_parameter();
    return 0;
}